﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class admin_Pro_Manage : System.Web.UI.Page
{
    string sql;
    string search = "";
    string cc = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        AdminCs.CheckLoginState();
        if (!IsPostBack)
        {
            list_bind();
            if (Request.QueryString["dd"] == "del")
            {
                dd_del();
            }
        } 
    }

    private void list_bind()
    {

        SqlConnection conn = Class1.DBconnection();
        //sql = "select * from wjOrder order by OR_ID desc";
        sql = "select * from wjOrder where OR_ID in (select Max(OR_ID) from wjOrder group by OR_User)";

        SqlDataAdapter da = new SqlDataAdapter(sql, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DataTable dt = ds.Tables[0];


       
        if (dt.Rows.Count > 0)
        {
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = ds.Tables[0].DefaultView;

            pds.AllowPaging = true;
            pds.PageSize = 17;
            int curPage;

            if (Request.QueryString["page"] != null)
            {
                curPage = Convert.ToInt32(Request.QueryString["page"]);
            }
            else
            {
                curPage = 1;
            }

            pds.CurrentPageIndex = curPage - 1;
            this.Repeater1.DataSource = pds;
            this.Repeater1.DataBind();
            this.Label1.Text += "<a>共有<font color=red><b>" + ds.Tables[0].Rows.Count.ToString() + "</b></font>条记录</a>&nbsp;";
            this.Label1.Text += "<a>每页显示<font color=red><b>" + pds.PageSize + "</b></font>条</a>&nbsp;";
            this.Label1.Text += "<a>共<font color=red><b>" + pds.PageCount.ToString() + "</b></font>页</a>&nbsp;";
            this.Label1.Text += "<a>当前第<font color=red><b>" + curPage.ToString() + "</b></font>页</a>&nbsp;&nbsp;";
            if (curPage == 1)
            {
                this.Label1.Text += "<a>首页</a>&nbsp;";
                this.Label1.Text += "<a>上一页</a>&nbsp;";
            }
            else
            {
                this.Label1.Text += "<a href='PS_Manage.aspx?page=1'>首页</a>&nbsp;";
                this.Label1.Text += "<a href='PS_Manage.aspx?page=" + (curPage - 1).ToString() + "'>上一页</a>&nbsp;&nbsp;";
            }
            if (curPage == pds.PageCount)
            {
                this.Label1.Text += "<a>下一页</a>&nbsp;";
                this.Label1.Text += "<a>尾页</a>&nbsp;";
            }
            else
            {
                this.Label1.Text += "<a href='PS_Manage.aspx?page=" + (curPage + 1).ToString() + "'>下一页</a>&nbsp;";
                this.Label1.Text += "<a href='PS_Manage.aspx?page=" + pds.PageCount.ToString() + "'>尾页</a>&nbsp;";
            }

            string HtmlSelectString = "<select onchange=\"javascript:window.location=this.value\">";
            for (int i = 1; i <= pds.PageCount; i++)
            {
                if (i == curPage)
                {
                    HtmlSelectString += "<option value=?page=" + i + " selected>第" + i + "页</option>";
                }
                else
                {
                    HtmlSelectString += "<option value=?page=" + i + ">第" + i + "页</option>";
                }
            }
            HtmlSelectString += "</select>";

            this.Label1.Text += "<a>" + HtmlSelectString + "</a>";
        }
        else
        {
            this.Label1.Text = "当前没有记录";
        }
        ds.Dispose();
        da.Dispose();
        conn.Close();
        conn.Dispose();
    }
    private void dd_del()
    {
        int id = int.Parse(Request.QueryString["ID"]);
        string sql = "delete from wjOrder where OR_Uid=" + id;
        string sql2 = "delete from Cart where G_UID=" + id;
        Class1.ExecSql(sql);
        Class1.ExecSql(sql2);
        Class1.AlertShow("删除成功！", "PS_Order.aspx");
    }

}
